package com.work.washer.aa;

import org.springframework.data.annotation.CreatedDate;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.AttachmentType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTreeType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 
 * @TableName goods
 */
@Erupt(name = "商品")
@Table(name = "goods")
@Entity
public class Goods extends BaseModel {


    /**
     * 
     */
    @ManyToOne //多对多
    @JoinColumn(name = "class_id")
    @EruptField(
            views = @View(title = "类目", column = "text"),
            edit = @Edit(title = "类目",
                    type = EditType.REFERENCE_TREE, search = @Search, notNull = true,
                    referenceTreeType = @ReferenceTreeType(pid = ""))
    )
    private GoodsClass goodsClass;

    /**
     * 标题
     */
    @EruptField(
            views = @View(title = "标题"),
            edit = @Edit(title = "标题" ) //相当于 type = EditType.INPUT
    )
    private String title;

    /**
     * 价格
     */
    @EruptField(
            views = @View(title = "价格"),
            edit = @Edit(title = "价格" ) //相当于 type = EditType.INPUT
    )
    private BigDecimal price;

    /**
     * 主图
     */
    @EruptField(
            views = @View(title = "主图"),
            edit = @Edit(title = "主图", type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(type = AttachmentType.Type.IMAGE, maxLimit = 1))
    )
    private String thumb;

    /**
     * 创建人id
     */
    @ManyToOne //多对多
    @JoinColumn(name = "user_id")
    @EruptField(
            views = @View(title = "发布人", column = "name"),
            edit = @Edit(title = "发布人",
                    type = EditType.REFERENCE_TREE, search = @Search, notNull = true,
                    referenceTreeType = @ReferenceTreeType(pid = ""))
    )
    private User user;

    /**
     * 
     */
    @EruptField(
            views = @View(title = "详情"),
            edit = @Edit(title = "详情", type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(type = AttachmentType.Type.IMAGE, maxLimit = 1))
    )
    private String detail;

    @EruptField(
            views = @View(title = "创建时间"),
            edit = @Edit(title = "创建时间" )
    )
    @CreatedDate
    private Date createTime;

}